package com.weakteam.orderonline.administratorconsole.gwt.client.util.uploader.file;

import com.google.gwt.core.client.JsArray;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;

/**
 * @author Nail
 */
public class FileEvent extends GwtEvent<FileEvent.FileEventHandler> {

    public interface FileEventHandler extends EventHandler {

        void onFiles(FileEvent event);
    }

    public static final Type<FileEventHandler> TYPE = new GwtEvent.Type<FileEventHandler>();
    private final JsArray<File> files;

    /**
     * construct a file event with an array of associated files
     * @param files the files associated with this event
     */
    public FileEvent(JsArray<File> files) {
        this.files = files;
    }

    @Override
    public GwtEvent.Type<FileEventHandler> getAssociatedType() {
        return TYPE;
    }

    /**
     * gets the files associated with this event
     *
     * @return an array of files associated with this event
     */
    public JsArray<File> getFiles() {
        return this.files;
    }

    @Override
    protected void dispatch(FileEventHandler handler) {
        handler.onFiles(this);
    }
}
